#ifndef SESSION_REPOSITORY_H
#define SESSION_REPOSITORY_H

#include "base_repository.h"
#include "session.h"
#include "sqlite_wrapper.h"
#include <string>

/// @file session_repository.h
/// @brief Repository for Session table operations
///
/// This file defines the repository class for Session table operations
/// using the SQLite C API with RAII wrappers. Inherits from BaseRepository for
/// common CRUD operations.

/// @class SessionRepository
/// @brief Repository class for Session table operations
///
/// This class provides database operations for Session entities.
/// Inherits from BaseRepository for common CRUD operations.
class SessionRepository : public BaseRepository<Session>
{
private:
    DatabaseConnection& db_;

public:
    /// @brief Constructor
    /// @param db Reference to the DatabaseConnection object
    SessionRepository(DatabaseConnection& db) : db_(db)
    {
    }

    /// @brief Create a new session in the database
    /// @param session Reference to the session to create
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int create(Session& session) override;

    /// @brief Update an existing session in the database
    /// @param session Reference to the session to update
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int update(const Session& session) override;

    /// @brief Remove a session from the database by ID
    /// @param id The ID of the session to remove
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int remove(int id) override;

    /// @brief Find a session by ID
    /// @param id The ID of the session to find
    /// @return Optional containing the session if found, nullopt otherwise
    virtual std::optional<Session> findById(int id) override;

    /// @brief Get all sessions
    /// @return Vector containing all sessions
    virtual std::vector<Session> findAll() override;

    /// @brief Find a session by user ID
    ///
    /// @param user_id User ID to search for
    /// @return std::optional<Session> Session object if found, empty optional otherwise
    std::optional<Session> findByUserId(int user_id);

    /// @brief Get all active sessions
    ///
    /// @return std::vector<Session> Vector of all active Session objects
    std::vector<Session> findActiveSessions();

    /// @brief Create or replace a session in the database
    ///
    /// @param session Session object to create/replace
    /// @return REPO_SUCCESS if successful, error code otherwise
    int createOrReplace(Session& session);
};

#endif  // SESSION_REPOSITORY_H